package com.mapper;

import com.domain.Article;
import com.domain.BlogComment;
import com.domain.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {
//    @Select("SELECT * FROM t_comment Where id =#{id}")
//    public Comment findById(Integer id);
//
//    @Insert("INSERT INTO t_COMMENT(content,author,a_id)" +"values (#{content},#{author},#{aId}")
//    public int insertComment(Comment comment);
//
//    @Update("UPDATE t_comment SET content=#{content} WHERE id=#{id}")
//    public int updateComment(Comment comment);
//
//    @Delete("DELETE FROM t_comment WHERE id=#{id}")
//    public int deleteComment(Integer id);
//
//    Article selectArticle(int i);
   @Delete("DELETE FROM t_comment WHERE article_id=#{aid}")
   public void deleteCommentWithId(Integer aid);

    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC")
    public List<BlogComment> selectCommentWithPage(Integer aid);

    @Select("SELECT * FROM t_comment ORDER BY id DESC")
    public List<BlogComment> selectNewComment();

    @Insert("INSERT INTO t_comment (article_id, created,author,ip,content)" +
            " VALUES (#{articleId},#{created},#{author},#{ip},#{content})")
    public void pushComment(BlogComment comment);

    @Select("SELECT COUNT(1) FROM t_comment")
    public Integer countComment();

    @Select("SELECT t.*,a.title articleTitle FROM t_comment t,t_article a WHERE t.article_id=a.id ORDER BY t.id DESC")
    public List<BlogComment> selectComment();

    Comment findById(int i);
}
